<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div {
            position: absolute;
            left: 0;
            width: 100px;
            height: 100px;
            background-color: pink;
        }
        
        span {
            position: absolute;
            left: 0;
            top: 200px;
            display: block;
            width: 150px;
            height: 150px;
            background-color: purple;
        }
    </style>
</head>

<body>
    <button class="btn500">点击夏雨荷到500</button>
    <button class="btn800">点击夏雨荷到800</button>
    <span>夏雨荷</span>

</body>

<script>
    function animate(obj, x) {
        clearInterval(obj.timer);
        obj.timer = setInterval(function() {
            if (obj.offsetLeft == x) {
                clearInterval(obj.timer);
            } else {
                let move = (x - obj.offsetLeft) / 10;
                move = move >= 0 ? Math.ceil(move) : Math.floor(move);
                obj.style.left = obj.offsetLeft + move + 'px';
            }
        }, 15);
    };

    let span = document.querySelector('span');
    let but500 = document.querySelector('.btn500');
    but500.addEventListener('click', function() {
        animate(span, 500);
    });
    let but800 = document.querySelector('.btn800');
    but800.addEventListener('click', function() {
        animate(span, 800);
    });
</script>

</html>